package v1

import (
	"wms/service/impl"
	"wms/service/request"
	"wms/service/response"

	"github.com/icetech233/gin"
)

func (a *tenantApi) TenantList(c *gin.Context) {
	queryParams := c.Request.URL.Query()
	entType := queryParams.Get("ent_type")
	arg := new(request.QueryTenantRequest)
	if entType == supplier {
		arg.IsSupplier = &isFilter
	} else if entType == customer {
		arg.IsCustomer = &isFilter
	}
	outList := impl.TenantSrvImpl.List(c, *arg)
	response.OkWithData(outList, c)
}

func (a *tenantApi) TenantAdd(c *gin.Context) {
	param := new(request.AddTenantRequest)
	err := c.ShouldBindJSON(param)
	if err != nil {
		response.Fail(-1, "入参错误:"+err.Error(), param, c)
		return
	}
	err = impl.TenantSrvImpl.Add(c, param)
	if err != nil {
		response.Fail(-1, err.Error(), param, c)
		return
	}
	response.Ok(c)
}

func (a *tenantApi) TenantEdit(c *gin.Context) {
	param := new(request.EditTenantRequest)
	err := c.ShouldBindJSON(param)
	if err != nil {
		response.Fail(-1, "入参错误:"+err.Error(), param, c)
		return
	}
	err = impl.TenantSrvImpl.Edit(c, param)
	if err != nil {
		response.Fail(-1, err.Error(), param, c)
		return
	}
	response.Ok(c)
}
